﻿using FastJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MIO.Client.Util
{
    public class JsonUtil
    {

        private static readonly FastJson.JSONParameters CUSTOM_JSON_SETTING = new FastJson.JSONParameters() { EnableAnonymousTypes = false, UseExtensions = false, CamelCasePropertyNames = true, UseOptimizedDatasetSchema = false , UseTimestamp =true};

        public static T jsonString2Object<T>(string jsonString)
        {
            T obj = FastJson.JSON.ToObject<T>(jsonString, CUSTOM_JSON_SETTING); 
            return obj;
        }

        public static Object jsonString2Object(string jsonString,Type type)
        {
            Object obj = FastJson.JSON.ToObject(jsonString, type, CUSTOM_JSON_SETTING);
            return obj;
        }

        public static string object2JsonString(object obj)
        {
            string jsonString = FastJson.JSON.ToJSON(obj, CUSTOM_JSON_SETTING);
            return jsonString;
        }

    }
}
